﻿using System;
using System.Collections.Generic;
using YArchitech.Public;

namespace YJKMenuAssist
{
	public class CommandInfoReader
	{
		public static bool GetCommandInfos(ref CommandTableInfos commandTableInfos)
		{
			bool result;
			try
			{
				result = CommandInfoReader.ReadInfos(new Application().GetHYMenuInfos(), ref commandTableInfos);
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private static bool ReadInfos(VerticalMenuCommandTableInfos vmInfos, ref CommandTableInfos commandTableInfos)
		{
			List<TableInfos> list = new List<TableInfos>();
			foreach (VerticalMenuTableInfos verticalMenuTableInfos in vmInfos.TableInofList)
			{
				string tableName = verticalMenuTableInfos.TableName;
				List<CommandInfos> list2 = new List<CommandInfos>();
				foreach (VerticalMenuCommandInfos verticalMenuCommandInfos in verticalMenuTableInfos.CommandInfoList)
				{
					string cmdName = verticalMenuCommandInfos.CmdText.Replace("\r", "").Replace("\n", "");
					string cmdText = verticalMenuCommandInfos.CmdText;
					string dllName = verticalMenuCommandInfos.DllName;
					string className = verticalMenuCommandInfos.ClassName;
					string imageName = verticalMenuCommandInfos.ImageName;
					string tooltip = verticalMenuCommandInfos.Tooltip;
					string panelName = verticalMenuCommandInfos.PanelName;
					CommandInfos item = new CommandInfos(cmdName, cmdText, dllName, className, imageName, tooltip, panelName, true, tableName);
					list2.Add(item);
				}
				TableInfos item2 = new TableInfos(tableName, list2);
				list.Add(item2);
			}
			commandTableInfos = new CommandTableInfos(list);
			return true;
		}
	}
}
